<template>
  <div class="userlist-container">
    <!-- 面包屑导航 -->
    <el-breadcrumb separator="/">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>权限管理</el-breadcrumb-item>
      <el-breadcrumb-item>权限列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片组件 -->
    <el-card>
      <el-table :data="rightsList" height="250" border stripe style="width: 100%">
        <!-- 添加一个索引列 -->
        <el-table-column type="index" width="60px" label="#"></el-table-column>
        <el-table-column prop="id" label="权限ID" width="80px"></el-table-column>
        <el-table-column prop="authName" label="权限名称" ></el-table-column>
        <el-table-column prop="path" label="对应访问路径"></el-table-column>
        <el-table-column prop="level" label="权限层级">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.level==0" type="info">等级一</el-tag>
            <el-tag v-else-if="scope.row.level==1" type="success">等级二</el-tag>
            <el-tag v-else type="danger">等级三</el-tag>
          </template>
        </el-table-column>
        <!-- <el-table-column prop="create_time" label="操作" min-width="200px">
          <template slot-scope="scope">
            <el-button type="primary" icon="el-icon-edit" @click="editUser(scope.row.id)"></el-button>
            <el-button type="primary" icon="el-icon-delete" @click="deleteUser(scope.row.id)"></el-button>
          </template>
        </el-table-column> -->
      </el-table>
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="queryInfo.pagenum"
        :page-sizes="[20,50, 100]" :page-size="queryInfo.pagesize" layout="total, sizes, prev, pager, next, jumper"
        :total="total"></el-pagination>
    </el-card>
  </div>
</template>

<script>
  export default {
    data() {
      return {
        rightsList: [],
        queryInfo: {
          query: '',
          pagenum: 1,
          pagesize: 20
        },
        total: 0
      }
    },
    created() {
      this.getRightsList()
    },
    methods: {
      async getRightsList() {
        const result = await this.$http.get('rights/list', this.queryInfo)
        if (result.meta.status !== 200) return this.$message.error(result.meta.msg)
        this.rightsList = result.data
        console.log(this.rightsList)
        this.total = this.rightsList.length
        this.$message.success(result.meta.msg)
      },
      addRights() {

      },
      handleSizeChange(newsize) {
        console.log(newsize)
        this.queryInfo.pagesize = newsize
        this.getRightsList()
      },
      handleCurrentChange(newnum) {
        console.log(newnum)
        this.queryInfo.pagenum = newnum
        this.getRightsList()
      }
    }
  }
</script>

<style>
</style>
